package zdream.rockchronicle.screen;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;

import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;

import java.util.Objects;

import zdream.rockchronicle.RockChronicle;

/**
 * 开头的那个场景, 测试使用
 */
public class MainMenuScreen implements Screen {
	public final RockChronicle app;
	OrthographicCamera camera;

	public MainMenuScreen(RockChronicle app) {
		this.app = Objects.requireNonNull(app);

		camera = new OrthographicCamera();
		camera.setToOrtho(false, app.width, app.height);
	}

	@Override
	public void show() {
		app.assets.storage = app.levels.storage;
		app.assets.startLoading();
	}

	@Override
	public void render(float delta) {
		Gdx.gl.glClearColor(0, 0, 0.2f, 1);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

		camera.update();

		BitmapFont font16 = app.graphics.font16;
		SpriteBatch uiBatch = app.graphics.uiBatch;
		uiBatch.setProjectionMatrix(camera.combined);


		// 检查资源加载情况
		int remain = app.assets.hasLoaded();
		String text;

		uiBatch.begin();
		text = (remain > 0) ? "还剩 " + remain : "还剩 0 : 点击屏幕开始";
		font16.draw(uiBatch, "这是 Demo!!! ", 100, 150);
		font16.draw(uiBatch, text, 100, 100);

		text = "字体" + FreeTypeFontGenerator.DEFAULT_CHARS;
		font16.draw(uiBatch, text, 100, 30);
		uiBatch.end();

		if (Gdx.input.isTouched() && remain == 0) {
			app.game.setScreen(new LevelScreen(app));
			dispose();
		}
	}

	@Override
	public void resize(int width, int height) {
		// resize
	}

	@Override
	public void pause() {
		// pause
	}

	@Override
	public void resume() {
		// resume
	}

	@Override
	public void hide() {
		// hide
	}

	@Override
	public void dispose() {
		// dispose
	}
}
